<%@ page contentType="text/html;charset=utf-8"%>
<%@ page
	import="java.io.*, java.sql.*, java.util.*, java.text.*, napal.*, util.*"%>
<%@ page import="org.apache.ibatis.*"%>
<%@ page import="java.util.Date"%>
<%
	request.setCharacterEncoding("utf-8");
%>
<%@page import="java.util.Calendar"%>
<%
	request.setCharacterEncoding("utf-8");

	Calendar now = Calendar.getInstance();
	int year = now.get(Calendar.YEAR);
	int month = now.get(Calendar.MONTH) + 1;

	String _year = request.getParameter("year");
	String _month = request.getParameter("month");

	if (_year != null)
		year = Integer.parseInt(_year);

	if (_month != null)
		month = Integer.parseInt(_month);

	now.set(year, month - 1, 1); //출력할 년도, 월로 설정

	year = now.get(Calendar.YEAR); //변화된 년, 월
	month = now.get(Calendar.MONTH) + 1;

	int end = now.getActualMaximum(Calendar.DAY_OF_MONTH); //해당월의 마지막 날짜
	int w = now.get(Calendar.DAY_OF_WEEK); //1~7(일~토)
	
	String m = (String)session.getAttribute("managerID");
	String u = (String)session.getAttribute("userID");
	
	String cmd = request.getParameter("cmd");
%>
<%
	if (cmd!=null) {
%>
<a href="PlanInsert.jsp" class="btn btn-inverse btn-mini">삭제</a>
<%
	int id2 = Integer.parseInt(request.getParameter("id"));
		RentalHome.deletePlan(id2);
%>
<script language=javascript>
				self.window.alert("일정을 삭제하였습니다.");
				location.href = "Main.jsp?id=<%=m%>";
</script>
<%
	}
%>
<%@ include file="./Header.jsp"%>
</td>
</TR>
<TR HEIGHT="100">
	<td>
			<table>
				<TR>
					<td>
						<%
							if (manager != null) {
						%> <a href="PlanInsert.jsp" class="btn btn-inverse btn-small">일정등록</a>
						<%
							}
						%>
					</td>
				</TR>
				<TR>
					<Td>
						<div class="alert alert-error" align="center">정기점검 일정</div>
					</Td>
				</TR>
				<TR>
					<TD>
						<table>
							<tr height="30">
								<td align="center"><a
									href="Main.jsp?year=<%=year%>&month=<%=month - 1%>&id=<%if (m != null) {%>
		<%=m%>
		<%} else if (u != null) {%>
		<%=u%>
		<%}%>">◀</a>
									<b><%=year%>年 <%=month%>月</b> <a
									href="Main.jsp?year=<%=year%>&month=<%=month + 1%>&id=<%if (m != null) {%>
		<%=m%>
		<%} else if (u != null) {%>
		<%=u%>
		<%}%>">▶</a>
								</td>
							</tr>
						</table>

						<table width="210" border="0" cellpadding="2" cellspacing="1"
							bgcolor="#cccccc">
							<tr height="25">
								<td align="center" bgcolor="#e6e4e6"><font color="red">일</font></td>
								<td align="center" bgcolor="#e6e4e6">월</td>
								<td align="center" bgcolor="#e6e4e6">화</td>
								<td align="center" bgcolor="#e6e4e6">수</td>
								<td align="center" bgcolor="#e6e4e6">목</td>
								<td align="center" bgcolor="#e6e4e6">금</td>
								<td align="center" bgcolor="#e6e4e6"><font color="blue">토</font></td>
							</tr>
							<%
								int newLine = 0;
								//1일이 어느 요일에서 시작하느냐에 따른 빈칸 삽입
								out.println("<tr height='25'>");
								for (int i = 1; i < w; i++) {
									out.println("<td bgcolor='#ffffff'>&nbsp;</td>");
									newLine++;
								}

								String fc, bg;
								for (int i = 1; i <= end; i++) {

									fc = (newLine == 0) ? "red" : (newLine == 6 ? "blue"
											: "#000000");
									bg = "#ffffff";
									out.println("<td align='center' bgcolor=" + bg
											+ "><font color=" + fc + ">" + i + "</font></td>");
									newLine++;
									if (newLine == 7 && i != end) {
										out.println("</tr>");
										out.println("<tr height='25'>");
										newLine = 0;
									}
								}

								while (newLine > 0 && newLine < 7) {
									out.println("<td bgcolor='ffffff'>&nbsp;</td>");
									newLine++;
								}
								out.println("</tr>");
							%>
						</table>
					</td>
					<td width=30%>
						<TABLE>
							<%
								for (Plan g : RentalHome.planview(year, month)) {
							%>
							<TR>
								<TD><%=g.get시작날짜()%>~</TD>
								<TD><%=g.get끝날짜()%> :</TD>
								<TD><%=g.get일정명()%></TD>
								<TD>
									<%
										if (manager != null) {
									%> <input type=hidden name="id" value="<%=g.get일정번호()%>">
									<a href="Main.jsp?id=<%=g.get일정번호()%>&cmd=<%=g.get일정번호()%>"
									class="btn btn-inverse btn-mini">삭제</a>
								</TD>
							</TR>
							<%
								}
								}
							%>
						</TABLE>
					</TD>
					<td width=50%><%if(u!=null){ %>
						<table>
						<tr>
						<td><p align="left">
							<%for(book b : RentalHome.getbook2((String)session.getAttribute("userID"))){
							List<book> b2=RentalHome.getbook(b.get모델번호(),b.get보관사용처());
							if(b2.isEmpty()!=false){
							%>
						<font size = 5 color="gray"><p align="left">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<%=(String)session.getAttribute("userName") %>님이 예약중인 모델</p></font>
		<font color="gray">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;예약 기자재 정보 : </font>
		&nbsp;&nbsp;<font color="red"> <%= b.get카테고리명()%>&nbsp;&nbsp;<%= b.get모델명()%>&nbsp;&nbsp; <%=b.get보관사용처() %> </font>
		&nbsp;&nbsp;&nbsp;&nbsp;<a href="BookDelete_s.jsp" onclick="return confirm('예약을 취소하시겠습니까?');">예약 취소</a>
							<%}
							else if(b2.isEmpty()==false){
								%>
								<font size = 5 color="red"><p align="left">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;예약한 기자재가 대여가능 합니다.</font></p>
<font color="gray">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;예약 기자재 정보 : </font>
&nbsp;&nbsp;<font color="red"> <%= b.get카테고리명()%>&nbsp;&nbsp;<%= b.get모델명()%>&nbsp;&nbsp; <%=b.get보관사용처() %> </font>
&nbsp;&nbsp;&nbsp;&nbsp;<a href="BookDelete_s.jsp" onclick="return confirm('예약을 취소하시겠습니까?');">예약 취소</a>
								<%
						}
						}
						%></p>
						</td>
						</tr>
						<tr><td><font size = 5 color="gray"><p align="left">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<%=(String)session.getAttribute("userName") %>님이 대여신청중인 모델</p></font><br>
<font color="red">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;※
<% for(RentalWait r : RentalHome.rentalWait((String)session.getAttribute("userID"))){%>
<%= r.get모델명()%>&nbsp;&nbsp;&nbsp;&nbsp;<a href="EquipmentRentalModify_s.jsp">신청서 수정</a>
&nbsp;&nbsp;&nbsp;&nbsp;<a href="RentalDelete_s.jsp" onclick="return confirm('신청을 취소하시겠습니까?');">신청 취소</a>

<br>
<% } %></font>
</td></tr></table><%} %>
					</td>
				</TR>
			</table>
	</TD>
</tr>
<tr>
	<td>
		<table>
			<tr>
				<TD><a href="Notice.jsp"> <img src="../img/iyong.JPG"
						class="img-rounded"></a></TD>
				<TD><a href="TotalList.jsp"><img src="../img/mok.JPG"
						class="img-rounded"></a></TD>
			</TR>
		</table>
		
	</td>
</tr>
<TR HEIGHT="50">
	<TD><%@ include file="./bottom.jsp"%></TD>
</TR>
</TABLE>
</body>
</html>